package com.digitalchina.lxnsy.viewholder;

import android.app.Activity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.digitalchina.lxnsy.R;
import com.digitalchina.lxnsy.activity.old.NewAgricultureActivity;
import com.digitalchina.lxnsy.entity.ProductPlanListVO;
import com.digitalchina.lxnsy.interfaces.IMyNhbPos;
import com.digitalchina.lxnsy.toolkit.DateStyle;
import com.digitalchina.lxnsy.toolkit.DateUtil;
import com.digitalchina.lxnsy.toolkit.GotoUtil;
import com.digitalchina.lxnsy.xml.AdminXML;
import com.jude.easyrecyclerview.adapter.BaseViewHolder;

/**
 * ================================================
 * 项目名称：BigData
 * 类描述：
 * 包名：com.digitalchina.bigdata.viewholder
 * 创建人：郑皓
 * 创建时间：2018/8/21 11:10
 * 修改备注：
 * ================================================
 */

public class StandardProductionHolder extends BaseViewHolder<ProductPlanListVO> {

    private TextView tvName;
    private TextView tvMode;
    private TextView tvStage;
    private TextView tvTime;
//    private TextView tvCity;
    private TextView tvArea;
//    private TextView tvIncome;
//    private TextView tvExpend;

    private LinearLayout layoutEdit;
    private LinearLayout layoutDelete;
    private LinearLayout layoutNewAgr;

    private IMyNhbPos iMyNhbPos;
    private View view;


    public StandardProductionHolder(ViewGroup parent, IMyNhbPos iMyNhbPos) {
        super(parent, R.layout.item_standard_production_v2);
        tvName = $(R.id.tv_name);
        tvMode = $(R.id.tv_mode);
        tvStage = $(R.id.tv_stage);
        tvTime = $(R.id.tv_time);
        view = $(R.id.view);
//        tvCity = $(R.id.tv_city);
        tvArea = $(R.id.tv_area);
//        tvIncome = $(R.id.tv_income);
//        tvExpend = $(R.id.tv_expend);

        layoutEdit = $(R.id.layout_edit);
        layoutDelete = $(R.id.layout_delete);
        layoutNewAgr = $(R.id.layout_new_agr);

        this.iMyNhbPos = iMyNhbPos;
    }

    @Override
    public void setData(final ProductPlanListVO data) {
        super.setData(data);

        tvName.setText(data.getCropType().getName() + "");
//        tvMode.setText(data.getPlantType() != null ? data.getPlantType().getName() : "树龄" + data.getTreeAge() + "年");
        tvStage.setText(data.getPhaseMsgInfo() != null ? data.getPhaseMsgInfo().getPhaseName() : "");
//        tvCity.setText(data.getFullAddress());

        tvArea.setText(data.getPlantSize() + "亩");

//        tvIncome.setText(StringUtil.isStrEmpty(data.getTotalEarning()) ? "￥0.00" : "￥" + data.getTotalEarning());
//        tvExpend.setText(StringUtil.isStrEmpty(data.getTotalPayout()) ? "￥0.00" : "￥" + data.getTotalPayout());


        tvTime.setText(DateUtil.StringToString(data.getSeedDate(), DateStyle.YYYY_MM_DD_EN));

        //ERP不展示新农艺
        if (AdminXML.getFarmOperation(getContext()).equals("1")) {
            layoutNewAgr.setVisibility(View.GONE);
            view.setVisibility(View.GONE);
        } else {
            layoutNewAgr.setVisibility(View.VISIBLE);
            view.setVisibility(View.VISIBLE);
        }

        layoutEdit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                iMyNhbPos.edit(getAdapterPosition());
            }
        });

        layoutDelete.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                iMyNhbPos.del(getAdapterPosition());
            }
        });

        layoutNewAgr.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                GotoUtil.gotoActivity((Activity) getContext(), NewAgricultureActivity.class, "ID", data.getProductStandard().getId());
            }
        });
    }

}
